package com.qianfeng.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianfeng.dto.Page;
import com.qianfeng.entity.Registration;
import com.qianfeng.mapper.RegistrationMapper;
import com.qianfeng.service.RegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RegistrationServiceImpl implements RegistrationService {
    @Autowired
    private RegistrationMapper registrationMapper;

    @Override
    public void addRegistration(Registration registration) {
        registrationMapper.addRegistration(registration);
    }

    @Override
    public void updateRegistration(Registration registration) {
        registrationMapper.updateRegistration(registration);
    }

    @Override
    public void deleteRegistration(Integer rId) {
        registrationMapper.deleteRegistration(rId);
    }

    @Override
    public Registration getRegistrationById(Integer rId) {
        return registrationMapper.getRegistrationById(rId);
    }

    @Override
    public Page getRegistrationPage(Integer pageNo, Integer pageSize) {
        Page page = new Page();
        PageHelper.startPage(pageNo, pageSize);
        List<Registration> registrationList = registrationMapper.getRegistrationList();
        PageInfo<Registration> pageInfo = new PageInfo<>(registrationList);
        page.setObj(pageInfo.getList());
        page.setPageCount(pageInfo.getPages());
        page.setHasNext(pageInfo.isHasNextPage());
        return page;
    }
}
